﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.DALFactory;
using ECCIT;
using System.Linq;
using OgilvyOne.UKNow.IDAL;
using OgilvyOne.UKNow.DAL;
using OgilvyOne.UKNow.ServiceReference;
using OgilvyOne.Model;
using OgilvyOne.Utility;
using OgilvyOne.BLL;
using OgilvyOne.UKNow.Globalization;

namespace OgilvyOne.UKNow.BLL
{
    public class LogMapKeyWordsBLL
    {
        public int LanguageID { get; set; }
        public LogMapKeyWordsBLL(int langID) { this.LanguageID = langID; }

        /// <summary>
        /// 向MapkeywordLog表添加日志
        /// </summary>
        /// <param name="dmm">MapkeyModel字典</param>
        /// <param name="commt_ID">评论ID</param>
        /// <param name="commt_type">评论状态</param>
        public void InsertLog(Dictionary<MapKeyWordsModel,int> dmm,int commt_ID,int commt_type)
        {
            LogKeyWordsDAL lkw = new LogKeyWordsDAL((LanguageType)this.LanguageID);
            lkw.InsertLog(dmm, commt_ID, commt_type);
            
        }

        public string GetKeywordsXml()
        {
            LogKeyWordsDAL dal = new LogKeyWordsDAL((LanguageType)this.LanguageID);
            return dal.GetKeywordsXml();
        }

        //查找重复出现的关键字返回重复出现关键字与重复次数
        /// <summary>
        /// 
        /// </summary>
        /// <param name="strtext"></param>
        /// <returns></returns>
        public Dictionary<MapKeyWordsModel, int> seleRepetKeyWordsModelList(string strtext)
        {
            LogKeyWordsDAL lkw = new LogKeyWordsDAL((LanguageType)this.LanguageID);
            IList<MapKeyWordsModel> MwmIL = lkw.GetAllLogKeyWordsModels();

            string Vx;
            char[] Vxa;
            Dictionary<MapKeyWordsModel, int> dmm = new Dictionary<MapKeyWordsModel, int>();

            foreach (MapKeyWordsModel Mwm in MwmIL)
            {
                Vx = strtext.Replace(Mwm.Name, "a");
                if (Vx != Mwm.Name)
                {
                    Vxa = Vx.ToCharArray();
                    var vxx = from vv in Vxa
                              where vv == 'a'
                              select vv;

                    if (vxx.Count() > 0)
                        dmm.Add(Mwm, vxx.Count());

                }
            }

            return dmm;
        }
    }
}
